package com.ryl.yomall.weball.controller;

import com.ryl.yomall.cart.client.CartFeignClient;
import com.ryl.yomall.model.cart.CartInfo;
import com.ryl.yomall.model.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;

/**
 * @Date 13:07
 * @Author ryl
 */
@Controller
public class CartController {
    @Autowired
    private CartFeignClient cartFeignClient;
    //加入购物车
    @GetMapping("addCart.html")
    public String addCart(Long skuId,Integer skuNum,HttpSession session){


        CartInfo cartInfo=cartFeignClient.addToCart (skuId,skuNum  );
        session.setAttribute ( "cartInfo",cartInfo );
//        session.setMaxInactiveInterval ( 30 );

        return "redirect:http://cart.yomall.com/addToCart.html";
    }
    @GetMapping("/addToCart.html")
    public String addToCart(Model model,HttpSession session){

        CartInfo cartInfo = (CartInfo) session.getAttribute ( "cartInfo" );
        model.addAttribute ( "cartInfo", cartInfo);
        return "cart/addCart";
    }
    @GetMapping("/cart.html")
    public String cart(){
        return "cart/index";
    }
}
